package com.jiazhong.example.project.shoppingcart.controller;

import com.alibaba.fastjson.JSONArray;
import com.jiazhong.example.project.shoppingcart.service.BooksService;
import com.jiazhong.example.project.shoppingcart.service.impl.BooksServiceImpl;
import com.jiazhong.example.project.shoppingcart.util.JsonResult;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/books")
public class BooksController extends BaseController {

    private BooksService booksService = new BooksServiceImpl();

    public void find(HttpServletRequest request, HttpServletResponse response) throws IOException {
        JsonResult all = booksService.findAll();
        response.setContentType("application/json;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.print(JSONArray.toJSONString(all));
    }
}
